package com.nkzy.mapper;

import com.nkzy.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UserMapper {

    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectById(Integer id);

    @Select("SELECT * FROM user")
    List<User> selectAll();

    @Insert("INSERT INTO user(username, password, nickname, email, user_pic, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{nickname}, #{email}, #{userPic}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(User user);

    @Update("UPDATE user SET username = #{username}, password = #{password}, nickname = #{nickname}, " +
            "email = #{email}, user_pic = #{userPic}, update_time = #{updateTime} WHERE id = #{id}")
    void update(User user);

    @Delete("DELETE FROM user WHERE id = #{id}")
    void deleteById(Integer id);
}